﻿@model KRM.Core.vTriggerDetail
@{
    ViewBag.Title = "edittrigger";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="container-fluid">
    @if (!string.IsNullOrEmpty(ViewBag.msg) && ViewBag.msg == "success")
    {
        <div class="alert alert-success">
            <button type="button" class="close" data-dismiss="alert">×</button>
            <strong>Success.</strong> Update new success!
        </div>
    }
    else if (!string.IsNullOrEmpty(ViewBag.msg) && ViewBag.msg == "error")
    {
        <div class="alert alert-error">
            <button type="button" class="close" data-dismiss="alert">×</button>
            @ViewBag.error
        </div>
    }
    <div class="row-fluid">
        <div class="span12">
            <div class="box">
                <div class="box-title">
                    <h3><i class="icon-edit"></i>Edit trigger in @Model.TaskName</h3>
                </div>
                <div class="box-content">

                    @using (Html.BeginForm("EditTrigger", "Scenario", FormMethod.Post, new { @class = "form-horizontal" }))
                    {
    

                        <input type="hidden" value="@Model.TaskID" name="taskid" id="hfTaskid" />
                        <input type="hidden" name="dayinweek" id="hfdayinweek" />
                        <input type="hidden" name="months" id="hfmonths" />
                        <input type="hidden" name="daysinmonths" id="hfdaysinmonths" />
                        <input type="hidden" name="TaskAdvanceID" value="@Model.TaskAdvanceID" />
                        <input type="hidden" name="TriggerID" value="@Model.TriggerID" />
                        <div class="control-group">
                            <label class="control-label">Run type</label>
                            <div class="controls">
                                <select name="index" id="runtype">
                                    <option value="4" @(Model.RunTypeName.Equals("OneTime") ? "selected=selected" : "")>One time</option>
                                    <option value="1" @(Model.RunTypeName.Equals("Daily") ? "selected=selected" : "")>Daily</option>
                                    <option value="2" @(Model.RunTypeName.Equals("Weekly") ? "selected=selected" : "")>Weekly</option>
                                    <option value="3" @(Model.RunTypeName.Equals("Monthly") ? "selected=selected" : "")>Monthly</option>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">Start time</label>
                            <div class="controls">
                                @*<input type="text" name="date" id="date" class="input-large datepick">*@
                                <div id="datetimepicker2" class="input-append">
                                    <input data-format="MM/dd/yyyy HH:mm:ss PP" type="text" name="datestart" value="@Model.StartTime" id="datestart" required="required"  style="width: 173px;"/>
                                    <span class="add-on">
                                        <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                                    </span>
                                </div>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">Enable</label>
                            <div class="controls">
                                @Html.CheckBoxFor(model => model.Enable)
                                @*                                <input type="checkbox" name="Enable" @(Model.Enable == true ? "checked=checked" : "") >*@
                            </div>
                        </div>
                        <div class="control-group ctr-daily" @(Model.RunTypeName.Equals("Daily") ? "style=display:block" : "")>
                            <label class="control-label">Recur every</label>
                            <div class="controls">
                                <input type="number" name="every" id="every" class="input-small" placeholder="days" value="1" @(Model.RunTypeName.Equals("Daily") ? "" : "disabled=disabled") required="required">
                                days
                            </div>
                        </div>
                        <div class="control-group ctr-weekly" @(Model.RunTypeName.Equals("Weekly") ? "style=display:block" : "")>
                            <label class="control-label">
                                Select days
                                <small>ctrl + click to select many</small></label>
                            <div class="controls">
                                <select multiple="multiple" id="dayinweek" @(Model.RunTypeName.Equals("Weekly") ? "" : "disabled=disabled") required="required" style="height: 80px;">
                                    <option value="1">Monday</option>
                                    <option value="2">Tuesday</option>
                                    <option value="3">Wednesday</option>
                                    <option value="4">Thursday</option>
                                    <option value="5">Friday</option>
                                    <option value="6">Staturday</option>
                                    <option value="0">Sunday</option>
                                </select>
                            </div>
                        </div>
                        <div class="control-group ctr-monthly" @(Model.RunTypeName.Equals("Monthly") ? "style=display:block" : "")>
                            <label class="control-label">
                                Months
                                <small>ctrl + click to select many</small></label>
                            <div class="controls">
                                <select multiple="multiple" id="months" @(Model.RunTypeName.Equals("Monthly") ? "" : "disabled=disabled") required="required" style="height: 80px;">
                                    <option value="1">January</option>
                                    <option value="2">February</option>
                                    <option value="3">March</option>
                                    <option value="4">April</option>
                                    <option value="5">May</option>
                                    <option value="6">June</option>
                                    <option value="7">July</option>
                                    <option value="8">August</option>
                                    <option value="9">September</option>
                                    <option value="10">October</option>
                                    <option value="11">November</option>
                                    <option value="12">December</option>
                                </select>
                            </div>
                        </div>
                        <div class="control-group ctr-monthly" @(Model.RunTypeName.Equals("Monthly") ? "style=display:block" : "")>
                            <label class="control-label">
                                Days
                                <small>ctrl + click to select many</small></label>
                            <div class="controls">
                                <select multiple="multiple" id="daysinmonths" @(Model.RunTypeName.Equals("Monthly") ? "" : "disabled=disabled") required="required" style="height: 80px;">
                                    <option value="1">1</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                    <option value="6">6</option>
                                    <option value="7">7</option>
                                    <option value="8">8</option>
                                    <option value="9">9</option>
                                    <option value="10">10</option>
                                    <option value="11">11</option>
                                    <option value="12">12</option>
                                    <option value="13">13</option>
                                    <option value="14">14</option>
                                    <option value="15">15</option>
                                    <option value="16">16</option>
                                    <option value="17">17</option>
                                    <option value="18">18</option>
                                    <option value="19">19</option>
                                    <option value="20">20</option>
                                    <option value="21">21</option>
                                    <option value="22">22</option>
                                    <option value="23">23</option>
                                    <option value="24">24</option>
                                    <option value="25">25</option>
                                    <option value="26">26</option>
                                    <option value="27">27</option>
                                    <option value="28">28</option>
                                    <option value="29">29</option>
                                    <option value="30">30</option>
                                    <option value="31">31</option>
                                </select>
                            </div>
                        </div>
                        <p class="p-advance" @(Model.RunTypeName.Equals("OneTime") ? "" : "style=display:block")><a href="javascript:;" title="click to show advance option" style="padding: 0">Advance</a></p>
                        <div class="panel-advance" @(Model.RunTypeName.Equals("OneTime") ? "" : "style=display:block")>
                            <div class="control-group">
                                <label class="control-label">
                                    <input type="checkbox" class="loop-task" @(Model.RepeatEvery != null && Model.RepeatEvery > 0 ? "checked=checked" : "") />
                                    Loop task in</label>
                                <div class="controls">
                                    <input type="text" name="minutes" class="minutes" value="@(Model.RepeatEvery != null && Model.RepeatEvery > 0 ? KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.RepeatEvery)) : 15)" @(Model.RepeatEvery != null && Model.RepeatEvery > 0 ? "" : "disabled=disabled") style="width: 20px" required="required" />
                                    <select name="chooseminutes" class="choose-minutes" style="width: 80px" @(Model.RepeatEvery != null && Model.RepeatEvery > 0 ? "" : "disabled=disabled")>
                                        <option value="1" @(Model.RepeatEvery != null && Model.RepeatEvery > 0 && KRM.Core.Tool.Utilities.ConvertChooseMinute(Convert.ToInt32(Model.RepeatEvery), KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.RepeatEvery))) == 1 ? "selected=selected" : "")>Minutes</option>
                                        <option value="60" @(Model.RepeatEvery != null && Model.RepeatEvery > 0 && KRM.Core.Tool.Utilities.ConvertChooseMinute(Convert.ToInt32(Model.RepeatEvery), KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.RepeatEvery))) == 60 ? "selected=selected" : "")>Hours</option>
                                        <option value="1440" @(Model.RepeatEvery != null && Model.RepeatEvery > 0 && KRM.Core.Tool.Utilities.ConvertChooseMinute(Convert.ToInt32(Model.RepeatEvery), KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.RepeatEvery))) == 1440 ? "selected=selected" : "")>day</option>
                                    </select>
                                    on
                                <input type="text" name="hours" value="@(Model.Duration != null && Model.Duration > 0 ? KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.Duration)) : 1)" style="width: 20px" @(Model.Duration != null && Model.Duration > 0 ? "" : "disabled=disabled") class="hours" required="required" />
                                    <select name="choosehours" style="width: 80px" @(Model.Duration != null && Model.Duration > 0 ? "" : "disabled=disabled") class="choose-hours">
                                        <option value="1" @(Model.Duration != null && Model.Duration > 0 && KRM.Core.Tool.Utilities.ConvertChooseMinute(Convert.ToInt32(Model.Duration), KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.Duration))) == 1 ? "selected=selected" : "")>Minutes</option>
                                        <option value="60" @(Model.Duration != null && Model.Duration > 0 && KRM.Core.Tool.Utilities.ConvertChooseMinute(Convert.ToInt32(Model.Duration), KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.Duration))) == 60 ? "selected=selected" : "")>Hours</option>
                                        <option value="1440" @(Model.Duration != null && Model.Duration > 0 && KRM.Core.Tool.Utilities.ConvertChooseMinute(Convert.ToInt32(Model.Duration), KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.Duration))) == 1440 ? "selected=selected" : "")>day</option>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">
                                    <input type="checkbox" class="stop-task" @(Model.IsStop != null && Model.IsStop > 0 ? "checked=checked" : "") />
                                    Stop task if runs over</label>
                                <div class="controls">
                                    <input type="text" name="stopminutes" class="stop-minutes" value="@(Model.IsStop != null && Model.IsStop > 0 ? KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.IsStop)) : 1)" style="width: 20px" @(Model.IsStop != null && Model.IsStop > 0 ? "" : "disabled=disabled") required="required" />
                                    <select name="choosestopminutes" style="width: 80px" @(Model.IsStop != null && Model.IsStop > 0 ? "" : "disabled=disabled") class="choose-stop-minutes">
                                        <option value="1" @(Model.IsStop != null && Model.IsStop > 0 && KRM.Core.Tool.Utilities.ConvertChooseMinute(Convert.ToInt32(Model.IsStop), KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.IsStop))) == 1 ? "selected=selected" : "")>Minutes</option>
                                        <option value="60" @(Model.IsStop != null && Model.IsStop > 0 && KRM.Core.Tool.Utilities.ConvertChooseMinute(Convert.ToInt32(Model.IsStop), KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.IsStop))) == 60 ? "selected=selected" : "")>Hours</option>
                                        <option value="1440" @(Model.IsStop != null && Model.IsStop > 0 && KRM.Core.Tool.Utilities.ConvertChooseMinute(Convert.ToInt32(Model.IsStop), KRM.Core.Tool.Utilities.ConvertIntMinute(Convert.ToInt32(Model.IsStop))) == 1440 ? "selected=selected" : "")>day</option>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">
                                    <input type="checkbox" class="expired" @(Model.Expire != null ? "checked=checked" : "") />
                                    Time expired</label>
                                <div class="controls">
                                    <div id="datetimepicker3" class="input-append">
                                <input data-format="MM/dd/yyyy HH:mm:ss PP" type="text" name="Expireddate" value="@(Model.Expire ?? DateTime.Now)" class="expireddate" style="width: 173px;" @(Model.Expire != null ? "" : "disabled=disabled") required="required"/>
                                <span class="add-on">
                                    <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                                </span>
                            </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-actions">
                            <button type="submit" class="btn btn-primary btn-create-trigger">Update</button>
                        </div>
                    }

                </div>
            </div>
        </div>
    </div>
</div>
